package com.jgp.glmeeting.controller;

import com.jgp.glmeeting.model.Meeting;
import com.jgp.glmeeting.model.Template;
import com.jgp.glmeeting.service.MeetingService;
import com.jgp.glmeeting.service.TemplateService;
import com.jgp.sys.common.controller.JGPController;
import com.jgp.sys.common.pojo.LabelValue;
import com.jgp.sys.ui.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/glMeeting/templateApiController")
public class TemplateApiController extends JGPController {
    @Autowired
    private TemplateService templateService;
    @Autowired
    private MeetingService meetingService;
    /**
     * 下拉查询所有会议
     */
    @RequestMapping("/queryAllmeeting")
    public Result queryAllmeeting(Model model, Meeting m){
        List<Meeting> lists = meetingService.queryAll(m);
        List<LabelValue> collect = lists.stream().map(mm ->{
            return new LabelValue(mm.getName(),mm.getId(),null);
        }).collect(Collectors.toList());
        return ajaxRe("ldata",collect);
    }

    /**
     * 下拉列表查询所有模板
     */
    @RequestMapping("/queryAllTem")
    public Result queryAllTem(Model model){
        List<Template> lists = templateService.queryAllTem();
        List<LabelValue> collect = lists.stream().map(tt ->{
            return new LabelValue(tt.getName(),tt.getId(),null);
        }).collect(Collectors.toList());
        return ajaxRe("ldata",collect);
    }

    /**
     * 添加人员跳转
     */
    @RequestMapping("/addUsersTZ")
    public Result addInform(Model model,String[] usersID){
   /*     for (int i = 0; i<usersID.length  ; i++) {
            System.out.print(usersID[i]);
        }*/
        model.addAttribute("usersID",usersID);
      //  return ajaxRe(true).addData("usersID",usersID);
        return ajaxRe(true);
    }

    /**
     * 更换模板
     */
@RequestMapping("/changeA")
    public Result changeA(Model model,String str){
//    System.out.print(str);
Template t=templateService.queryById(str);
//model.addAttribute("content",t.getContent());
   return ajaxRe(true).addData("content",t.getContent());
   // return ajaxRe(true);
}




}
